package com.guli.product.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guli.common.utils.R;
import com.guli.product.entity.BrandEntity;
import com.guli.product.entity.CategoryEntity;
import com.guli.product.service.BrandService;
import com.guli.product.service.CategoryService;
import com.guli.product.vo.BrandVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import com.guli.product.entity.CategoryBrandRelationEntity;
import com.guli.product.service.CategoryBrandRelationService;


/**
 * 品牌分类关联
 * @author zzb
 * @email 1626131069@qq.com
 * @date 2023-10-21 10:18:56
 */
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;
    /**
     * 根据catId查询所有的品牌信息
     * @param catId
     * @return
     */
    @GetMapping("/brands/list")
    public R brandList(@RequestParam(value = "catId", required = false) Long catId) {
        List<BrandVo> brandVos = categoryBrandRelationService.brandList(catId);
        return R.ok().put("data", brandVos);
    }

    /**
     * 展示关联分类
     * @param params
     * @return
     */
    @GetMapping("/catelog/list")
    public R list(@RequestParam Map<String, Object> params) {
        List<CategoryBrandRelationEntity> categoryBrandRelationEntities = categoryBrandRelationService.queryPage(params);
        return R.ok().put("data", categoryBrandRelationEntities);
    }


    /**
     * 品牌与分类关联信息
     * @param id
     * @return
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);
        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 保存关联分类信息
     * @param categoryBrandRelation
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation) {
        categoryBrandRelationService.saveategoryBrandRelation(categoryBrandRelation);
        return R.ok();
    }


    /**
     * 修改关联分类
     * @param categoryBrandRelation
     * @return
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation) {
        categoryBrandRelationService.updateById(categoryBrandRelation);
        return R.ok();
    }

    /**
     * 删除关联分类
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        categoryBrandRelationService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
